package com.example.alaporres;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.alaporres.NearbyAdapter.ViewHolder;
import com.jac.alapores.domain.Alapores;

public class AlaporesAdapter extends BaseAdapter {
	private Activity parentActivity;
	private int itemLayoutId;
	private ArrayList<Alapores> dataSource;
	private LayoutInflater inflater;
   
	// constructor for adapter
	public AlaporesAdapter(Context context){
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public void setData(ArrayList<Alapores> alaporeslist){
		dataSource = alaporeslist;
	}
	
	public int getCount(){
		return dataSource.size();
	}
	
	public Alapores getAlapores(Long alaporesId, String alaporesName){
		Iterator<Alapores> alaporesiterator = dataSource.iterator();
		Alapores lThisAlapores = new Alapores();
		while (alaporesiterator.hasNext())
		{
			Alapores alapores = (Alapores) alaporesiterator.next();
			if (alapores.getID().equals(alaporesId) && alapores.getName().equalsIgnoreCase(alaporesName))
			{
				lThisAlapores = alapores;
			}
		}
		return lThisAlapores;
	}
	
	@Override
	public View getView(int pos, View convertView, ViewGroup parentView) {
		ViewHolder holder;
		if (convertView == null) {
			convertView	=  inflater.inflate(R.layout.activity_army, null);
			
			holder = new ViewHolder();
			
			holder.mNameTxt 		= (TextView) convertView.findViewById(R.id.tv_name);
			holder.mAddressTxt 		= (TextView) convertView.findViewById(R.id.tv_address);
			holder.mHereNowTxt 		= (TextView) convertView.findViewById(R.id.tv_here_now);
			holder.mDistanceTxt 	= (TextView) convertView.findViewById(R.id.tv_distance);
			holder.mRibbonImg		= (ImageView) convertView.findViewById(R.id.iv_ribbon);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Alapores getItem(int position) {
		// TODO Auto-generated method stub
		Alapores lAlap = dataSource.get(position);
		lAlap = getAlapores(lAlap.getID(), lAlap.getName());
		return lAlap;
	}

}
